package com.lmiot.xyclick.AD.SDK;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.lmiot.xyclick.AD.GDT.GdtRewardVideoActivity;
import com.lmiot.xyclick.AD.GDT.GdtSplashActivity;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.XyNoticBean;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.DebugUtli;
import com.lmiot.xyclick.Util.FileUtils;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.callback.FileCallBack;
import java.io.File;
import okhttp3.Call;

public class ADSDK {
    public static String FolderFlag = "xyclick";
    public static String G_APPID = "1109810267";
    public static String G_REWARD_VIDEO_ID1 = "4071963056669384";
    public static String G_REWARD_VIDEO_ID2 = "4071963056669384";
    public static String G_REWARD_VIDEO_ID3 = "4071963056669384";
    public static String G_REWARD_VIDEO_ID4 = "4071963056669384";
    public static String G_REWARD_VIDEO_ID5 = "4071963056669384";
    public static String G_SPLASH_ID01 = "5080488412519748";
    public static String G_SPLASH_ID02 = "7062884206612187";
    public static final String HOST = "https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick";
    private static final String TAG = "ADSDK";
    public static String appFlag = "xyclick";
    public static boolean mIsGDT = false;
    public static OnADResultListener mOnADResultListener = null;
    public static String mUploadVersion = "";
    public static String nowVersion = getMetaDataValue(MyApp.getContext(), "CHANNEL");
    private static final ADSDK ourInstance = new ADSDK();
    public static final String saveFileEnd = "xyf";
    public static boolean showShare = false;
    private Intent mIntent;

    public interface OnADFinishListener {
        void result(boolean z);
    }

    public interface OnADPermissionListener {
        void result(boolean z, String str);
    }

    public interface OnADResultListener {
        void result(boolean z, String str);
    }

    public static String getMetaDataValue(Context context, String str) {
        try {
            ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128);
            if (applicationInfo.metaData == null) {
                return "BG";
            }
            String string = applicationInfo.metaData.getString(str);
            if (TextUtils.isEmpty(string)) {
                return "BG";
            }
            return string;
        } catch (Exception e) {
            e.printStackTrace();
            return "BG";
        }
    }

    public static ADSDK getInstance() {
        return ourInstance;
    }

    private ADSDK() {
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void adMethod(Context context, boolean z, OnADResultListener onADResultListener) {
        mOnADResultListener = onADResultListener;
        if (z) {
            LogUtil.d(TAG, "AD类型：GDT开屏");
            Intent intent = new Intent(context, GdtSplashActivity.class);
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        } else {
            Intent intent2 = new Intent(context, GdtRewardVideoActivity.class);
            this.mIntent = intent2;
            intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(this.mIntent);
    }

    public void chosADShow(final Context context, final boolean z, final OnADFinishListener onADFinishListener) {
        LogUtil.d(TAG, "当前版本：" + nowVersion);
        if (mIsGDT) {
            if (onADFinishListener != null) {
                onADFinishListener.result(true);
            }
        } else if (!DebugUtli.isDebugVersion(MyApp.getContext())) {
            downNotic(new OnBasicListener() {
                /* class com.lmiot.xyclick.AD.SDK.ADSDK.AnonymousClass1 */

                @Override // com.lmiot.xyclick.inteface.OnBasicListener
                public void result(boolean z, String str) {
                    if (z) {
                        ADSDK.this.adMethod(context, z, new OnADResultListener() {
                            /* class com.lmiot.xyclick.AD.SDK.ADSDK.AnonymousClass1.AnonymousClass1 */

                            @Override // com.lmiot.xyclick.AD.SDK.ADSDK.OnADResultListener
                            public void result(boolean z, String str) {
                                LogUtil.d(ADSDK.TAG, "测试结果：" + ADSDK.nowVersion + ":" + ADSDK.mUploadVersion + ":" + z + "：" + str);
                                if (onADFinishListener != null) {
                                    onADFinishListener.result(true);
                                }
                            }
                        });
                        return;
                    }
                    if (onADFinishListener != null) {
                        onADFinishListener.result(true);
                    }
                }
            });
        } else if (onADFinishListener != null) {
            onADFinishListener.result(true);
        }
    }

    private void downNotic(final OnBasicListener onBasicListener) {
        ((GetBuilder) OkHttpUtils.get().url("https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick/noticText.txt")).build().connTimeOut(15000).writeTimeOut(15000).readTimeOut(15000).execute(new FileCallBack(MyApp.getContext().getFilesDir().getAbsolutePath(), "nt.xy") {
            @Override
            public void onError(Call call, Exception e, int id) {
                onBasicListener.result(false, "");
            }

            @Override
            public void onResponse(File file, int id) {
                if (file != null) {
                    try {
                        XyNoticBean xyNoticBean = (XyNoticBean) new Gson().fromJson(FileUtils.readFileToString(file), XyNoticBean.class);
                        if (xyNoticBean != null) {
                            DataUtil.nowNoicBean = xyNoticBean;
                            ADSDK.showShare = xyNoticBean.isShowShare01();
                            ADSDK.mUploadVersion = xyNoticBean.getUploadVersion();
                            if (ADSDK.mUploadVersion.contains(ADSDK.nowVersion)) {
                                onBasicListener.result(false, "");
                            } else {
                                onBasicListener.result(true, "");
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
